<template>
	<view class="my-partner-page comm-page-bg-1">
		<!-- #ifndef  H5 -->
		<custom-navbar is-back title="我的合伙人" ></custom-navbar>
		<!-- #endif -->
		
		<view class="my-partner__header flex">
			<view class="title">我的合伙人</view>
			<view class="input flex">
				<u-icon name="search" color="#999999" size="28"></u-icon>
				<u-input v-model="params.keywords"  :border="false" placeholder="搜索合伙人" @blur="searchHandler" />
			</view>
			
		</view>
		
	<!-- 	<view class="empty-box" v-if="isEmpty">
			<u-empty text="暂无数据" mode="list"></u-empty>
		</view> -->
		
		<view class="my-partner__body">
			<mescroll-uni ref="mescrollRef" bgColor="white" top="100rpx" @init="mescrollInit" :down="downOption"
				:up="upOption" @down="downCallback" @up="upCallback">
				<MyPartnerItem v-for="(item,index) in lists" :key="index" :row="item" @upCallback="upCallback"></MyPartnerItem>
			</mescroll-uni>
		</view>
		
	</view>
</template>

<script>
	import MyPartnerItem from './components/my-partner-item.vue'
	import {
		founders,
	} from "@/api/user";
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin],
		components: {
			MyPartnerItem
		},
		data() {
			return {
				loading: false,
				finished: false,
				searchValue: '',
				lists: [],
				downOption: {
					auto: false, // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					auto: true, // 不自动加载
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						icon: "/static/images/empty/order.png",
						tip: "暂无合伙人", // 提示
						fixed: true,
						top: "200rpx",
					},
				},
				params: {
					page_no: 1,
					page_size: 10,
					keywords: ''
				}
			}
		},
		computed: {
			isEmpty() {
				if (this.finished) {
					return !this.list.length
				}
				return false
			}
		},
		onReachBottomDistance() {
			
		},
		onPullDownRefresh() {
		},
		methods: {
			/**
			 * 接口在这里请求
			 * 请求到数据后，需要对数据做处理，确定需要用到的每个字段都要存在。
			 */
			getJsonData() {
				
			},
			/**
			 * 失焦事件，要不要，重新请求数据。
			 */
			searchHandler() {
				this.lists = [];
				let page = {
					num: 1,
					size: 10
				}
				this.upCallback(page);
			},
			
			upCallback(page) {
				this.params.page_no = page.num;
				this.params.page_size = page.size;
				this.loading = true
				this.finished = false
				founders(this.params)
				.then((res) => {
					if (page.num == 1) this.lists = []; //如果是第一页需手动置空列表
					this.lists = this.lists.concat(res.lists); //追加新数据
					this.mescroll.endBySize(res.lists.length, res.count);
				})
				.catch((err) => {
					this.mescroll.endBySize();
				}).finally(() => {
					this.loading = false
					this.finished = true
					uni.stopPullDownRefresh()
				});
			},
		}
	}
</script>

<style scoped lang="scss">
uni-page-body {
	height: 100vh;
	
}
.my-partner-page {
	height: 100vh;
}
.empty-box {
	padding: 300rpx 50rpx;
}
.my-partner__header {
	
	padding: 20rpx 30rpx 0;
	.title {
		padding-right: 20rpx;
		font-weight: bold;
		font-size: 40rpx;
		color: #000000;
		
	}
	.input {
		flex: 1;
		padding-left: 20rpx;
		border-radius: 999px;
		background-color: #ffffff;
		
	}
	.u-input__input {
		
	}
}
.my-partner__body {
	padding: 20rpx;
}
</style>
